//
//  BankCardController.m
//  DianDangDai
//
//  Created by bhf on 2017/12/21.
//  Copyright © 2017年 bhf. All rights reserved.
//

#import "BankCardController.h"
#import "BankCell.h"
#import "BankCardModel.h"
#import "HomePageDetailController.h"
@interface BankCardController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation BankCardController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.title = @"安全设置";
    [self setupViewsTouch];
    self.navigationItem.backBarButtonItem = BarButtonItem;
    // Do any additional setup after loading the view.
}

- (void)requestData {
    self.dataArray = [NSMutableArray array];
    NSString *urlString = [NSString stringWithFormat:@"%@OPT=1004&sign=%@",API_LOGIN_URL_STRING,USER_SIGN];
    [[CDHttpHelper defaultCDHttpHelper] get:urlString params:nil success:^(id responseObj)
     {
         
         NSDictionary *dict = [responseObj objectFromJSONData];
         NSLog(@"%@",dict);
         for (NSDictionary *dic in dict[@"banks"]) {
             BankCardModel *model = [BankCardModel mj_objectWithKeyValues:dic];
             [self.dataArray addObject:model];
         }
         [self.tableView reloadData];
     } failure:^(NSError *error) {
         
     } showHUD:YES];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    BankCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bank_cell" forIndexPath:indexPath];
    BankCardModel *model = self.dataArray[indexPath.row];
    [cell setModel:model];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 120;
}


- (void)setupViewsTouch {
    UITapGestureRecognizer *tapGesturRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
   
    [_bottomView addGestureRecognizer:tapGesturRecognizer];
}
- (void)tapAction:(id)tap {
   
    UIStoryboard *board = [UIStoryboard storyboardWithName:@"HomePage" bundle:[NSBundle mainBundle]];
    HomePageDetailController *hpdc = [board instantiateViewControllerWithIdentifier:@"hpdc"];
    hpdc.hidesBottomBarWhenPushed = YES;
    hpdc.titleStr = @"取现绑卡";
    NSString *urlString = [NSString stringWithFormat:@"%@OPT=1047&sign=%@",API_LOGIN_URL_STRING,USER_SIGN];
    hpdc.filepath = [NSURL URLWithString:urlString];
    [self showViewController:hpdc sender:self];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
